package com.itcast.demoone

import android.os.Bundle
import android.widget.ArrayAdapter
import android.widget.Spinner
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class FormActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_form)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        // 1. 获取下拉框
        val citySpinner = findViewById<Spinner>(R.id.citySpinner)
        // 2. 设置下拉框的数据
        val cityArray = arrayOf("北京", "上海", "广州", "深圳")
        // 3. 通过一个适配器把数据绑定到下拉框
        val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, cityArray)
        // 4. 把适配器设置给下拉框
        citySpinner.adapter = adapter
    }
}